import request from './request'

// 公告数据类型
export interface AnnouncementData {
  id: number
  title: string
  content: string
  type: 'notice' | 'news' | 'policy' | 'other'
  status: 'draft' | 'published' | 'archived'
  priority: 'low' | 'medium' | 'high'
  publishTime?: string
  expireTime?: string
  author: string
  createTime: string
  updateTime: string
}

// 获取公告列表
export const getAnnouncementList = () => {
  return request({
    url: '/announcements/list',
    method: 'post',
    data: {}
  })
}

// 获取公告分页列表
export const getAnnouncementPage = (params: {
  current: number
  size: number
  title?: string
  type?: string
  status?: string
  priority?: string
}) => {
  return request({
    url: '/announcements/page',
    method: 'post',
    data: params
  })
}

// 新增公告
export const addAnnouncement = (announcement: Omit<AnnouncementData, 'id' | 'createTime' | 'updateTime'>) => {
  return request({
    url: '/announcements/add',
    method: 'post',
    data: announcement
  })
}

// 编辑公告
export const updateAnnouncement = (announcement: AnnouncementData) => {
  return request({
    url: '/announcements/update',
    method: 'post',
    data: announcement
  })
}

// 删除公告
export const deleteAnnouncement = (id: number) => {
  return request({
    url: '/announcements/delete',
    method: 'post',
    data: { id }
  })
}

// 获取公告详情
export const getAnnouncementDetail = (id: number) => {
  return request({
    url: '/announcements/detail',
    method: 'post',
    data: { id }
  })
}

// 发布公告
export const publishAnnouncement = (id: number) => {
  return request({
    url: '/announcements/publish',
    method: 'post',
    data: { id }
  })
}

// 归档公告
export const archiveAnnouncement = (id: number) => {
  return request({
    url: '/announcements/archive',
    method: 'post',
    data: { id }
  })
}